package com.test.tool.demo.websocket;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;

import java.security.Principal;
import java.util.Map;

/**
 * 握手成功之后的消息处理
 *
 * @author 小八
 * @date 2022年04月25日15:32
 */
@Slf4j
public class EhomeHandshakeHandler extends DefaultHandshakeHandler {

    @Override
    protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
        //设置认证用户
        return (Principal) attributes.get("user");
    }

}
